// pages/video/video.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    winWidth: 0,
    winHeight: 0,
    currentTab: 0,
    list1:[1],
    list2:[1]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const db = wx.cloud.database();
    db.collection('MV').where({
      name:'mv'
    })
    .get({
      success: (res)=>{
        //res.data是包含以上定义的两条记录的数据
        console.log(res.data);
        console.log(this);
        this.setData({
          list1:res.data
        })

        var query = wx.createSelectorQuery();
        var that = this;
        query.select('.thelist').boundingClientRect(function (rect) {
          // console.log(rect.width)
          console.log(rect.height)
          that.setData({
            height: rect.height + 'px'
          })
        }).exec();
      }
    })

    var that = this;
    wx.getSystemInfo({
            success: function(res){
                that.setData({
                    winWidth: res.windowWidth,
                    winHeight: res.windowHeight
                });
            }
        });

        db.collection('recommend').where({
          name:'recommend'
        })
        .get({
          success: (res)=>{
            //res.data是包含以上定义的两条记录的数据
            console.log(res.data);
            console.log(this);
            this.setData({
              list2:res.data
            })
    
            var query = wx.createSelectorQuery();
            var that = this;
            query.select('.thelist').boundingClientRect(function (rect) {
              // console.log(rect.width)
              console.log(rect.height)
              that.setData({
                height: rect.height + 'px'
              })
            }).exec();
          }
        })
    
        var that = this;
        wx.getSystemInfo({
                success: function(res){
                    that.setData({
                        winWidth: res.windowWidth,
                        winHeight: res.windowHeight
                    });
                }
            });
  },
  
   //  tab切换
   swichNav: function(e){
    var that = this;
    if(this.data.currentTab === e.target.dataset.current){
        return false;
    }else{
        that.setData({
            currentTab: e.target.dataset.current
        })
    }
},

bindChange: function(e){
    var that = this;
    that.setData({currentTab: e.detail.current});
},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    wx.cloud.callFunction({
      // 云函数名称
      name: 'add',
      // 传给云函数的参数
      data: {
        a: 1,
        b: 2,
      },
      success: function(res) {
        console.log(res.result.sum) // 3
      },
      fail: console.error
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})